package com.itheima.controller;

import com.itheima.server.WebSocketServer;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @program: itcast-MyRPC
 * @description: 核心控制器
 * @author: zhanghz001
 * @create: 2021-02-20 11:08
 **/
@RestController
public class WebSocketController {
    @RequestMapping("im")
    public ModelAndView page() {
        return new ModelAndView("ws");
        //
    }
    
    @RequestMapping("/push/{toUserId}")
    public ResponseEntity<String> pushToWeb(String message, @PathVariable String toUserId) throws Exception {
        boolean flag = WebSocketServer.sendInfo(message, toUserId);
        return flag ? ResponseEntity.ok("消息推送成功...")
                : ResponseEntity.ok("消息推送失败,用户不在线...");
    }
}
